import request from '@/utils/request.js'
import store from '@/store/index'
/**
 *
 * @param {String} mobile 手机号
 * @param {String} code 验证码
 *@returns 登录
 */
export const reqLogin = (mobile, code) => {
  return request({
    method: 'post',
    url: '/v1_0/authorizations',
    data: {
      mobile,
      code
    }
  })
}

/**
 *
 * @param {Number} mobile 手机号
 * @returns 获取验证码
 */
export const reqSendCode = (mobile) => {
  return request({
    method: 'get',
    url: '/v1_0/sms/codes/' + mobile

  })
}

export const reqFollowUser = userId => {
  return request({
    method: 'post',
    url: '/v1_0/user/followings',
    data: {
      target: userId
    }
  })
}

export const reqUnFollowUser = userId => {
  return request({
    method: 'delete',
    url: '/v1_0/user/followings/' + userId
  })
}

export const reqAddLike = articleId => {
  return request({
    method: 'post',
    url: '/v1_0/article/likings',
    data: {
      target: articleId
    }
  })
}

export const reqDisLike = articleId => {
  return request({
    method: 'delete',
    url: '/v1_0/article/likings/' + articleId
  })
}

export const reqAddDisUnLikeArt = articleId => {
  return request({
    method: 'post',
    url: '/v1_0/article/dislikes',
    data: {
      target: articleId
    }
  })
}

export const reqDeleteDisLikeArt = articleId => {
  return request({
    method: 'delete',
    url: '/v1_0/article/dislikes/' + articleId
  })
}

export const reqRefreshToken = refreshToken => {
  return request({
    method: 'put',
    url: '/v1_0/authorizations',
    headers: {
      Authorization: `Bearer ${refreshToken}`
    }
  })
}

/**
 *
 * @returns 获取用户信息
 */
export const reqGetProfile = () => {
  const token = store.state.user.tokenInfo.token
  return request({
    method: 'get',
    url: '/v1_0/user/profile',
    headers: {
      Authorization: `Bearer ${token}`
    }
  })
}

export const reqGetUserInfo = () => {
  return request({
    method: 'get',
    url: '/v1_0/user'
  })
}

export const reqEditUserInfo = (obj) => {
  return request({
    method: 'patch',
    url: '/v1_0/user/profile',
    data: obj
  })
}

export const reqChangePhoto = (formData) => {
  return request({
    method: 'patch',
    url: '/v1_0/user/photo',
    data: formData
  })
}
